package common;

import java.util.HashMap;

import javax.swing.JPanel;
import javax.swing.JProgressBar;

import org.w3c.dom.Element;

import optimizers.commons.RunConfig;
import optimizers.ganeat.GA;

import fitness.Fitness;

public abstract class RunStarter {

	protected RunConfig config;
	protected String initIndiv;
	protected JPanel panelFitness;
	protected JPanel panelSpecies;
	protected JPanel panelIndiv;
	protected JProgressBar progressBar;
	protected Element fitnessElement;
	protected RunStatus runStatus;

	public void initialize(RunConfig config, String initIndiv,
			JPanel panelFitness, JPanel panelSpecies, JPanel panelIndiv,
			JProgressBar progressBar, Element fitnessElement) {
		this.runStatus = new RunStatus();
		this.config = config;
		this.initIndiv = initIndiv;
		this.panelFitness = panelFitness;
		this.panelSpecies = panelSpecies;
		this.panelIndiv = panelIndiv;
		this.progressBar = progressBar;
		this.fitnessElement = fitnessElement;
	}
	
	public abstract GA getGA();

	public abstract Fitness getFitnessFunction();

	public abstract String getName();

	public abstract HashMap<String, String> getDefaultParameters();

	public abstract void setParameters(HashMap<String, String> parameters);

	public abstract void start();

	public void stop() {
		runStatus.status = RunStatus.STOPPED;
	}

	public void pause() {
		runStatus.status = RunStatus.PAUSED;
	}

	public void resume() {
		runStatus.status = RunStatus.RUNNING;
		synchronized (runStatus.lock) {
			runStatus.lock.notifyAll();
		}
	}

	public boolean isRunning() {
		return runStatus.status == RunStatus.RUNNING;
	}

	public boolean isPaused() {
		return runStatus.status == RunStatus.PAUSED;
	}

}
